How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk (you can use the hotkey Ctrl + Alt + I to add a code chunk) and code the solution for the question.
Knit the rmarkdown file (hotkey: Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Blackboard.
Questions
Use the data of your own. Produce the following types of plots and comment on each plot. Plots should be meaningful. If you use the data we used in class, make sure the plots are not the same as the ones in the slides. All plots should have title, caption, appropriate labels on x and y-axis.
library(gganimate)
library(ggplot2)
library(tidyverse)
library(knitr)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
library(lubridate)
df$month <- month(df$Date_reported)
d1 <- df %>% group_by(month, Country) %>% summarise(mean = mean(Cumulative_deaths))
d2 <- d1 %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=Country, fill=Country, label=Country)) + geom_col()+
geom_text(aes(y = mean, label = Country), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Month {closest_state}', x='', y='Cumulative Number of Deaths', fill='Country', caption = 'As the months progress, the country with the largest cumulative number of deaths changes')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(month)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
library(lubridate)
df$week <- week(df$Date_reported)
d1 <- df %>% group_by(week, WHO_region) %>% summarise(mean = mean(Cumulative_cases))
d2 <- d1 %>% group_by(week) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=WHO_region, fill=WHO_region, label=WHO_region)) + geom_col()+
geom_text(aes(y = mean, label = WHO_region), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Week {closest_state}', x='', y='Cumulative Number of Cases', fill='WHO Region', caption = 'As the weeks progress, the WHO region with the most cases in total changes.')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(week)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)
df <- read_csv('RI.csv')
d1 <- df %>% group_by(Year, City) %>% summarise(mean = mean(Population))
d2 <- d1 %>% group_by(Year) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 7)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=City, fill= City, label=City)) + geom_col()+
geom_text(aes(y = mean, label = City), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Year {closest_state}', x='', y='Population', fill='City', caption = 'The ranks for the cities based on population has not changed dramatically over the past nine years.')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_states(Year)+
ease_aes("cubic-in-out")
animate(a1, nframes = 400, fps = 10)